const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    searchText: '', //搜索内容
    order: '',
    list: [],
    selectFlag: 0,
    typeList: [
      //   {
      //   text: '售后申请',
      //   list: []
      // },
      {
        text: '处理中',
        list: []
      }, {
        text: '申请记录',
        list: []
      }
    ],
  },

  toPage(e) {
    console.log(e);
    var obj = e.currentTarget.dataset.obj,
      flag = e.currentTarget.dataset.flag;

    if (flag == 'wuLiu') {
      wx.navigateTo({
        url: '/orderPackage/pages/returnGoods/returnGoods?order=' + JSON.stringify(obj) + '&flag=2',
      })
    } else {
      // 售后详情
      wx.navigateTo({
        url: '/orderPackage/pages/returnDetail/returnDetail?order=' + JSON.stringify(obj),
      })
    }
  },

  // 输入框编辑
  inputHandle(e) {
    var str = e.currentTarget.dataset.flag
    var val = e.detail.value
    this.setData({
      [str]: val
    })
    this.searchHandle()
    console.log(this.data);
  },
  onActiveChange(e) {
    console.log(e);
    this.setData({
      selectFlag: e.detail.index
    })

  },

  // 搜索
  searchHandle() {
    if (this.data.searchText == '') {
      wx.showToast({
        title: '请输入搜索内容',
        icon: 'none'
      })
      return
    }
    console.log(this.data.searchText);



  },

  delHandle() {
    this.setData({
      searchText: ''
    })
  },


  getList() {
    wx.showLoading({
      title: '',
    })
    var url = app.globalData.url + "ScOrder/listReturnOrder",
      typeList = this.data.typeList,
      that = this;
    app.wxRequest(url, {
        userId: app.globalData.userId
      }, res => {
        console.log(res);
        if (res.flag) {
          var datas = res.data;
          console.log(datas);
          typeList[0].list = []
          typeList[1].list = []

          datas.forEach(item => {
            if (item.returnStatus == 0 || item.returnStatus == 1) {
              typeList[0].list.push(item)
            } else {
              typeList[1].list.push(item)
            }
          })
          that.setData({
            typeList
          })

          wx.stopPullDownRefresh()
          wx.hideLoading()
        }
      },
      err => {
        console.log(err);
      })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.getList()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})